package com.example.shopping_mall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.shopping_mall.R;
import com.example.shopping_mall.bean.UiBrandBean;
import com.example.shopping_mall.bean.UiSecondBean;

import java.util.List;

//秒杀专区列表
public class SecondAdapter extends RecyclerView.Adapter<SecondAdapter.SecondHolder>{

    private Context context;
    private List<UiSecondBean> secondBeans;

    public SecondAdapter(Context context) {
        this.context = context;
    }

    public void setSecondBeans(List<UiSecondBean> secondBeans) {
        this.secondBeans = secondBeans;
    }

    @NonNull
    @Override
    public SecondHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SecondHolder(LayoutInflater.from(context).inflate(R.layout.seckill_list_item,null));
    }

    @Override
    public void onBindViewHolder(@NonNull SecondHolder holder, int position) {
        holder.seckillImage.setImageBitmap(secondBeans.get(position).getSeckillImage());
        holder.priceSpike.setText(String.valueOf(secondBeans.get(position).getPriceSpike()));
        holder.commodity.setText(secondBeans.get(position).getCommodity());
        holder.commodityDetail.setText(secondBeans.get(position).getCommodityDetail());
        holder.rightprice.setText(String.valueOf(secondBeans.get(position).getRightprice()));
    }

    @Override
    public int getItemCount() {
        return null==secondBeans?0:secondBeans.size();
    }

    class SecondHolder extends RecyclerView.ViewHolder{

        ImageView seckillImage;
        TextView priceSpike;
        TextView commodity;
        TextView commodityDetail;
        TextView rightprice;

        public SecondHolder(@NonNull View itemView) {
            super(itemView);

            seckillImage=itemView.findViewById(R.id.seckill_image);
            priceSpike=itemView.findViewById(R.id.price_spike);
            commodity=itemView.findViewById(R.id.commodity);
            commodityDetail=itemView.findViewById(R.id.commodity_detail);
            rightprice=itemView.findViewById(R.id.right_textView);
        }
    }
}
